package com.flashextended.apps.logomaker.beans.workareaobjects
{
	import com.flashextended.utils.graphics.bitmap.BitmapUtil;
	
	import flash.display.Bitmap;
	
	import mx.events.ResizeEvent;
	
	public class ImageOnStage extends GenericObject
	{
		public static const TYPE:String = "IMAGE";
		public static var idCount:int = 0;
		private var image:Bitmap;
		
		
		public function get originalBitmap():Bitmap {
			return _originalBitmap;
		}
		public function set originalBitmap(o:Bitmap):void {
			_originalBitmap = o;
		}
		protected var _originalBitmap:Bitmap;

		
		public function ImageOnStage(bmp:Bitmap)
		{
			super();
			var bUtil:BitmapUtil =new BitmapUtil();
			originalBitmap = bUtil.cloneBitmap(bmp);			
			this.bitmapImage = bmp;
			bitmapImage.smoothing = true;
			this.type = TYPE;
			ImageOnStage.idCount++;
			this.idImage = ImageOnStage.idCount+".png";
		}
		
		
		//setter and getter id image
		public function get idImage():String {
			return _idImage;
		}
		public function set idImage(o:String):void {
			_idImage = o;
		}
		protected var _idImage:String;

		
		public function set bitmapImage(val:Bitmap):void
		{
			try{
				this.removeChild(image);
			}catch(e:Error)
			{
				
			}
			image = val;
			this.addChild(image);
			this.objectWidth = image.width;
			this.objectHeight = image.height;
		}
		public function get bitmapImage():Bitmap
		{
			return image;
		}
		
		private var _brightness:Number=0;
		public function set brightness(val:Number):void
		{
			_brightness = val;
			var bUtil:BitmapUtil =new BitmapUtil();
			var newBMD:Bitmap = bUtil.brightness(originalBitmap, _brightness);
			adjustBMDDimensions(newBMD);
			this.bitmapImage = newBMD; 
		}
		public function get brightness():Number
		{
			return _brightness;
		}
		
		private var _contrast:Number=0;
		public function set contrast(val:Number):void
		{
			_contrast = val;
			var bUtil:BitmapUtil =new BitmapUtil();
			var newBMD:Bitmap = bUtil.contrast(originalBitmap, _contrast);
			adjustBMDDimensions(newBMD);
			this.bitmapImage = newBMD;			
		}
		public function get contrast():Number
		{
			return _contrast;
		}
		
		private var _saturation:Number=0;
		public function set saturation(val:Number):void
		{
			_saturation = val;
			var bUtil:BitmapUtil =new BitmapUtil();
			var newBMD:Bitmap = bUtil.saturation(originalBitmap, _saturation);
			adjustBMDDimensions(newBMD);
			this.bitmapImage = newBMD;		
		}
		public function get saturation():Number
		{
			return _saturation;
		}		
		
		private function adjustBMDDimensions(newbmp:Bitmap):void
		{
			newbmp.width = this.width;
			newbmp.height = this.height;			
		}			
		
		//BEGIN OPERATIONS
		override protected function moveX():void
		{
			
		}
		override protected function moveY():void
		{
			
		}
		override protected function changeW():void
		{
			this.width = objectWidth;
		}
		override protected function changeH():void
		{
			this.height = objectHeight;
		}
		override protected function resizeContainer(e:ResizeEvent):void
		{
			objectX = this.x;
			objectY = this.y;
			objectRotation = this.rotation;
			objectWidth = this.width;
			objectHeight = this.height;
			image.width = objectWidth;
			image.height = objectHeight;
		}				
	}
}